﻿Imports System.Drawing.Drawing2D
Imports System.ComponentModel

Public Class PTIC_Panel
    Inherits Windows.Forms.Panel

#Region "Déclaration des fonctions / constantes API"

#End Region

#Region "Enumérations"
    Public Enum nomThemePanel
        OMANE
        OMANEtabControl
        Standard
    End Enum
    Public Enum typeDegrade
        AERO
        OMANE
        Aucun
    End Enum

#End Region

#Region "Variables de classe"

#Region "Choix du thème"
    Private _theme As ThemeComposant
    Private _nomTheme As nomThemePanel
    Private _borderRight As Boolean
    Private _borderTop As Boolean
    Private _borderBottom As Boolean
    Private _borderLeft As Boolean
    Private _typeDegrade As typeDegrade
#End Region

#Region "Personnalisation du thème"

    Private _BackColorPerso As Boolean
    Private _BackColorAxeDegrade As Double
    Private _BackColorDegrade11 As Color
    Private _BackColorDegrade12 As Color
    Private _BackColorDegrade21 As Color
    Private _BackColorDegrade22 As Color

    Private _BorderPerso As Boolean
    Private _BorderColor_Left As Color
    Private _BorderColor_top As Color
    Private _BorderColor_right As Color
    Private _BorderColor_bottom As Color

#End Region

#End Region

#Region "Propriétés"

#Region "Choix du thème"

    <Browsable(True), Category("Thème")> _
     Public Property theme() As nomThemePanel
        Get
            Return _nomTheme
        End Get
        Set(ByVal value As nomThemePanel)
            Select Case value
                Case nomThemePanel.OMANE

                    Dim etat As etatComposant
                    If Me.Enabled Then etat = etatComposant.Enabled Else etat = etatComposant.Disabled

                    _nomTheme = value

                    Dim styleOMANEpnlSTD As _
                            New styleEtatComposant(My.Settings.OMANEPnlSTD_ColorDegradeStandard1, _
                                                   My.Settings.OMANEPnlSTD_ColorDegradeStandard2, _
                                                   Me.Font, _
                                                   Me.ForeColor, _
                                                   My.Settings.OMANE_ColorBorder, _
                                                   My.Settings.OMANE_AngleRoundRect)
                    Dim styleOMANEpnlMOUSEOVER As _
                            New styleEtatComposant(My.Settings.OMANEPnlSTD_ColorDegradeStandard1, _
                                                   My.Settings.OMANEPnlSTD_ColorDegradeStandard2, _
                                                   Me.Font, _
                                                   Me.ForeColor, _
                                                   My.Settings.OMANE_ColorBorder, _
                                                   My.Settings.OMANE_AngleRoundRect)
                    Dim styleOMANEpnlDIS As _
                            New styleEtatComposant(My.Settings.OMANEPnlSTD_ColorDegradeStandard1, _
                                                   My.Settings.OMANEPnlSTD_ColorDegradeStandard2, _
                                                   Me.Font, _
                                                   Me.ForeColor, _
                                                   My.Settings.OMANE_ColorBorder, _
                                                   My.Settings.OMANE_AngleRoundRect)

                    _theme = New ThemeComposant(styleOMANEpnlSTD, _
                                                styleOMANEpnlMOUSEOVER, _
                                                styleOMANEpnlDIS, etat)

                Case nomThemePanel.OMANEtabControl

                    Dim etat As etatComposant
                    If Me.Enabled Then etat = etatComposant.Enabled Else etat = etatComposant.Disabled

                    _nomTheme = value

                    Dim styleOMANEpnlSTD As _
                            New styleEtatComposant(My.Settings.OMANEPnlSTD_ColorDegradeTabCont1, _
                                                   My.Settings.OMANEPnlSTD_ColorDegradeTabCont2, _
                                                   Me.Font, _
                                                   Me.ForeColor, _
                                                   My.Settings.OMANE_ColorBorder, _
                                                   My.Settings.OMANE_AngleRoundRect)
                    Dim styleOMANEpnlMOUSEOVER As _
                            New styleEtatComposant(My.Settings.OMANEPnlSTD_ColorDegradeTabCont1, _
                                                   My.Settings.OMANEPnlSTD_ColorDegradeTabCont2, _
                                                   Me.Font, _
                                                   Me.ForeColor, _
                                                   My.Settings.OMANE_ColorBorder, _
                                                   My.Settings.OMANE_AngleRoundRect)
                    Dim styleOMANEpnlDIS As _
                            New styleEtatComposant(My.Settings.OMANEPnlSTD_ColorDegradeTabCont1, _
                                                   My.Settings.OMANEPnlSTD_ColorDegradeTabCont2, _
                                                   Me.Font, _
                                                   Me.ForeColor, _
                                                   My.Settings.OMANE_ColorBorder, _
                                                   My.Settings.OMANE_AngleRoundRect)

                    _theme = New ThemeComposant(styleOMANEpnlSTD, _
                                                styleOMANEpnlMOUSEOVER, _
                                                styleOMANEpnlDIS, etat)
            End Select
            Invalidate(True)
        End Set
    End Property

#End Region

#Region "Personnalisation du thème"
    '----- Propriétés s'affichant au dessus du thème retenu (permettant de personnaliser le thème retenu) ----
    'Faut il personnaliser les bordures
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BorderPerso() As Boolean
        Get
            Return _BorderPerso
        End Get
        Set(ByVal value As Boolean)
            Me._BorderPerso = value
            Invalidate(True)
        End Set
    End Property
    'Bordure gauche du panel
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BorderColor_Left() As Color
        Get
            Return _BorderColor_Left
        End Get
        Set(ByVal value As Color)
            Me._BorderColor_Left = value
            Invalidate(True)
        End Set
    End Property
    'Bordure haut du panel
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BorderColor_top() As Color
        Get
            Return _BorderColor_top
        End Get
        Set(ByVal value As Color)
            Me._BorderColor_top = value
            Invalidate(True)
        End Set
    End Property
    'Bordure droite du panel
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BorderColor_right() As Color
        Get
            Return _BorderColor_right
        End Get
        Set(ByVal value As Color)
            Me._BorderColor_right = value
            Invalidate(True)
        End Set
    End Property
    'Bordure bas du panel
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BorderColor_bottom() As Color
        Get
            Return _BorderColor_bottom
        End Get
        Set(ByVal value As Color)
            Me._BorderColor_bottom = value
            Invalidate(True)
        End Set
    End Property

    '----- Propriétés relatives à l'arrière plan dégradé -----
    'Paramétrage de l'emplacement de l'axe du dégradé
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BackColorAxeDegrade() As Double
        Get
            Return _BackColorAxeDegrade
        End Get
        Set(ByVal value As Double)
            Me._BackColorAxeDegrade = value
            Invalidate(True)
        End Set
    End Property
    'Paramétrage de la présence ou non d'un dégradé
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BackColorPerso() As Boolean
        Get
            Return _BackColorPerso
        End Get
        Set(ByVal value As Boolean)
            Me._BackColorPerso = value
            Invalidate(True)
        End Set
    End Property
    'Couleur 1 du dégradé en haut
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BackColorDegrade11() As Color
        Get
            Return _BackColorDegrade11
        End Get
        Set(ByVal value As Color)
            Me._BackColorDegrade11 = value
            Invalidate(True)
        End Set
    End Property
    'Couleur 2 du dégradé en haut
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BackColorDegrade12() As Color
        Get
            Return _BackColorDegrade12
        End Get
        Set(ByVal value As Color)
            Me._BackColorDegrade12 = value
            Invalidate(True)
        End Set
    End Property
    'Couleur 1 du dégradé en bas
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BackColorDegrade21() As Color
        Get
            Return _BackColorDegrade21
        End Get
        Set(ByVal value As Color)
            Me._BackColorDegrade21 = value
            Invalidate(True)
        End Set
    End Property
    'Couleur 2 du dégradé en bas
    <Browsable(True), Category("Thème - Personnalisation")> _
    Public Property BackColorDegrade22() As Color
        Get
            Return _BackColorDegrade22
        End Get
        Set(ByVal value As Color)
            Me._BackColorDegrade22 = value
            Invalidate(True)
        End Set
    End Property

#End Region

#Region "Thème OMANE"
    'Paramétrage de la présence ou non d'un dégradé
    <Browsable(True), Category("Thème OMANE")> _
    Public Property BorderRight() As Boolean
        Get
            Return _borderRight
        End Get
        Set(ByVal value As Boolean)
            Me._borderRight = value
            Invalidate(True)
        End Set
    End Property
    <Browsable(True), Category("Thème OMANE")> _
    Public Property BorderLeft() As Boolean
        Get
            Return _borderLeft
        End Get
        Set(ByVal value As Boolean)
            Me._borderLeft = value
            Invalidate(True)
        End Set
    End Property
    <Browsable(True), Category("Thème OMANE")> _
    Public Property BorderTop() As Boolean
        Get
            Return _borderTop
        End Get
        Set(ByVal value As Boolean)
            Me._borderTop = value
            Invalidate(True)
        End Set
    End Property
    <Browsable(True), Category("Thème OMANE")> _
    Public Property BorderBottom() As Boolean
        Get
            Return _borderBottom
        End Get
        Set(ByVal value As Boolean)
            Me._borderBottom = value
            Invalidate(True)
        End Set
    End Property
    <Browsable(True), Category("Thème OMANE")> _
    Public Property degrade() As typeDegrade
        Get
            Return _typeDegrade
        End Get
        Set(ByVal value As typeDegrade)
            Me._typeDegrade = value
            Invalidate(True)
        End Set
    End Property

#End Region

#End Region

#Region "Constructeur"
    Public Sub New()

        'Activation de la transparence
        SetStyle(ControlStyles.SupportsTransparentBackColor, True)

        'Activation du double buffering
        SetStyle(ControlStyles.UserPaint, True)
        SetStyle(ControlStyles.AllPaintingInWmPaint, True)
        SetStyle(ControlStyles.OptimizedDoubleBuffer, True)
        SetStyle(ControlStyles.ResizeRedraw, True)

        'Définition des styles d'affichage pour éviter le flicking
        'Définition du style à appliquer au bouton
        theme = nomThemePanel.OMANE

    End Sub
#End Region

#Region "Redéfinition de la méthode Paint"

    Protected Overrides Sub onPaint(ByVal e As PaintEventArgs)

        MyBase.OnPaint(e)

        'Récupération du contexte graphique du Panel
        Dim g As Graphics = e.Graphics

        'Récupération du style en cours
        Dim styleEnCours As styleEtatComposant = _theme.styleEnCours

        'Gestion des dégradés de thème
        If theme = nomThemePanel.OMANE And _typeDegrade = typeDegrade.AERO Then
            Styles.PaintDoubleDegrade(g, Me.ClientRectangle, _
                      Color.FromArgb(50, styleEnCours.backColor), _
                      Color.FromArgb(210, styleEnCours.backColor), _
                      styleEnCours.backColor, _
                      styleEnCours.backColor, 1)
        End If
        If (theme = nomThemePanel.OMANE And _typeDegrade = typeDegrade.OMANE) Or _
            theme = nomThemePanel.OMANEtabControl Then
            Styles.PaintDoubleDegrade(g, Me.ClientRectangle, _
                      styleEnCours.backColor, _
                      styleEnCours.backColor2, _
                      styleEnCours.backColor, _
                      styleEnCours.backColor, 1)
        End If

        'Gestion des dégradés personnalisés
        If _BackColorPerso Then
            Styles.PaintDoubleDegrade(g, Me.ClientRectangle, _
                                      BackColorDegrade11, _
                                      BackColorDegrade12, _
                                      BackColorDegrade21, _
                                      BackColorDegrade22, BackColorAxeDegrade)
        End If

        'Gestion des bordures de thème
        If theme = nomThemePanel.OMANE Or theme = nomThemePanel.OMANEtabControl Then
            Dim lpen As New Pen(styleEnCours.borderColor, 1)
            If _borderLeft Then g.DrawLine(lpen, 0, 0, 0, Me.Bounds.Height - 1)
            If _borderTop Then g.DrawLine(lpen, 0, 0, Me.Bounds.Width - 1, 0)
            If _borderRight Then g.DrawLine(lpen, Me.Bounds.Width - 1, 0, Me.Bounds.Width - 1, Me.Bounds.Height - 1)
            If _borderBottom Then g.DrawLine(lpen, 0, Me.Bounds.Height - 1, Me.Bounds.Width - 1, Me.Bounds.Height - 1)
            lpen.Dispose()
        End If

        'Gestion des bordures personnalisées
        If _BorderPerso Then
            g.DrawLine(New Pen(_BorderColor_Left, 1), 0, 0, 0, Me.Bounds.Height - 1)
            g.DrawLine(New Pen(_BorderColor_top), 0, 0, Me.Bounds.Width - 1, 0)
            g.DrawLine(New Pen(_BorderColor_right), Me.Bounds.Width - 1, 0, Me.Bounds.Width - 1, Me.Bounds.Height - 1)
            g.DrawLine(New Pen(_BorderColor_bottom), 0, Me.Bounds.Height - 1, Me.Bounds.Width - 1, Me.Bounds.Height - 1)
        End If
    End Sub

#End Region

#Region "Gestion des évènements"
    Private Sub PTIC_Panel_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        'Me.Invalidate()
    End Sub
#End Region


    'UserControl remplace la méthode Dispose pour nettoyer la liste des composants.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Requise par le Concepteur Windows Form
    Private components As System.ComponentModel.IContainer

    'REMARQUE : la procédure suivante est requise par le Concepteur Windows Form
    'Elle peut être modifiée à l'aide du Concepteur Windows Form.  
    'Ne la modifiez pas à l'aide de l'éditeur de code.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        components = New System.ComponentModel.Container()
    End Sub


End Class
